/**
 * 
 */
package cc3002;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

/**
 * JUnit Test class : WeirdFood
 * ----------------------------
 * We will test this class extending the FoodTest class.
 * @author Anibal Llanos Prado
 *
 */
public class WeirdFoodTest extends FoodTest {
	/**
	 * Setup. Fixtures are inherited.
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		food1=new WeirdFood(name1);
		food2=new WeirdFood(); food2.setName(name2);
		bites=3;
	}

	/**
	 * Test method for {@link cc3002.WeirdFood#bite(cc3002.HealthState)}.
	 */
	@Test
	public void testBite() {
		//Creating an altered Health State to test food2
		HealthState health=new HealthState(1);
		assertEquals(food1.bite(new HealthState()),300);
		assertEquals(food1.bite(new HealthState()),300);
		assertEquals(food1.bite(new HealthState()),300);
		assertEquals(food1.bite(new HealthState()),0);
		assertEquals(food2.bite(health),(int)(300*health.getFoodMultiplier()));
	}

	/**
	 * Since this method is defined with a random factor, the only way to test it is to
	 * eat Weird Foods and follow the evolution of a Health State iteratively until 
	 * an "unpredicted" change modifies the state. To a full explanation of how the test
	 * is implemented, look for the single comments in the source file.
	 * Test method for {@link cc3002.WeirdFood#modifyHealth(cc3002.HealthState)}.
	 */
	@Test
	public void testModifyHealth() {
		//Creating two altered Health States to test.
		HealthState health=new HealthState();
		//Creating Strings to store the food saver before and after the bite.
		String fsb, fsa;
		while(true){
			//Storing before, biting, storing after
			fsb=health.getFoodSaver();
			food1.bite(health);
			fsa=health.getFoodSaver();
			//If the good saver reaches its limit (returns to "0") the state must increase
			if(Integer.parseInt(fsa.substring(0,1))<Integer.parseInt(fsb.substring(0,1))){
				assertEquals(4, health.getState());
				break;
			}
			//Else if the bad saver reaches its limit (returns to "0")the state must decrease
			else if(Integer.parseInt(fsa.substring(1))<Integer.parseInt(fsb.substring(1))){
				assertEquals(2, health.getState());
				break;
			}
			//Else (none has changed) the state must be the same
			else assertEquals(3, health.getState());
		}

	}

	/**
	 * Test method for {@link cc3002.Food#setName(java.lang.String)}.
	 */
	@Test
	public void testSetName() {
		super.testSetName();
	}

	/**
	 * Test method for {@link cc3002.Food#getFullName()}.
	 */
	@Test
	public void testGetFullName() {
		super.testGetFullName();
	}

	/**
	 * Test method for {@link cc3002.Food#getName()}.
	 */
	@Test
	public void testGetName() {
		super.testGetName();
	}

	/**
	 * Test method for {@link cc3002.Food#setCalories(int)}.
	 */
	@Test
	public void testSetCalories() {
		super.testSetCalories();
	}

}
